﻿#ifndef TLVDATAMODELTYPEDEF_H
#define TLVDATAMODELTYPEDEF_H

/** Data Example:

{
    "name": "Test Project",
    "cmds": [
        {
            "name": "Panel1",
            "iic": [
                {"title": "Dual Link", "value": {"addr": "40", "hexstring": "00 45 5A", "readlen": ""}, "wait": "50"},
                {"title": "开背光", "value": {"addr": "1B", "hexstring": "83 01 FF FF 01 00 24", "readlen": ""}, "wait": "50"}
            ],
            "tlv": [
                {"title": "屏幕上电时序", "value": {"tag": "ED86", "hexstring": "02", "wait": "50"},
                {"title": "屏幕下电时序", "value": {"tag": "ED86", "hexstring": "03", "wait": "50"}
            ]
        },
        {
            "name": "Panel2",
            "iic": [
                {"title": "关背光", "value": {"addr": "1B", "hexstring": "83 00 00 00 00 00 24", "readlen": ""}, "wait": "50"},
                {"title": "读FE", "value": {"addr": "1B", "hexstring": "FE", "readlen": "32"}, "wait": "50"}
            ],
            "tlv": [
                {"title": "设置背光", "value": {"tag": "ED86", "hexstring": "04 FF"}, "wait": "50"}
            ]
        }
    ],
    "codes": [
        {"name": "tab-1", "title": "Example", "code": "// 在此编写JS脚本代码，例如：\nlet cnt = 0;  // 上下电计数\nwhile (Available()) {\n    SendTlv('ED86', '03');  // 下电\n    Sleep(3000);  // 休眠3000ms\n    SendTlv('ED86', '02');  // 上电\n    Sleep(2000);\n    ShowMsg(`${++cnt} 次`, 200);  // 字体大小200\n    Sleep(2000);\n}\nShowMsg('连接断开！');"}
    ]
}

*/

#include <QString>
#include <QList>

struct IICCmdModel {
    QString title;
    QString wait;

    struct Value {
        QString addr;
        QString hexstring;
        QString readlen;

        bool operator==(const Value& other) const {
            return addr == other.addr &&
                   hexstring == other.hexstring &&
                   readlen == other.readlen;
        }

        bool operator!=(const Value& other) const {
            return !(*this == other);
        }
    } value;

    bool operator==(const IICCmdModel& other) const {
        return title == other.title &&
               wait == other.wait &&
               value == other.value;
    }

    bool operator!=(const IICCmdModel& other) const {
        return !(*this == other);
    }
};

struct TlvCmdModel {
    QString title;
    QString wait;

    struct Value {
        QString tag;
        QString hexstring;

        bool operator==(const Value& other) const {
            return tag == other.tag &&
                   hexstring == other.hexstring;
        }

        bool operator!=(const Value& other) const {
            return !(*this == other);
        }
    } value;

    bool operator==(const TlvCmdModel& other) const {
        return title == other.title &&
               wait == other.wait &&
               value == other.value;
    }

    bool operator!=(const TlvCmdModel& other) const {
        return !(*this == other);
    }
};

struct CmdPageModel {
    QString name;
    QList<IICCmdModel> iic;
    QList<TlvCmdModel> tlv;

    bool operator==(const CmdPageModel& other) const {
        return name == other.name &&
               iic == other.iic &&  // QList 已经重载了 == 运算符
               tlv == other.tlv;    // QList 已经重载了 == 运算符
    }

    bool operator!=(const CmdPageModel& other) const {
        return !(*this == other);
    }
};

struct CodePageModel {
    QString name;
    QString title;
    QString code;

    bool operator==(const CodePageModel& other) const {
        return name == other.name &&
               title == other.title &&
               code == other.code;
    }

    bool operator!=(const CodePageModel& other) const {
        return !(*this == other);
    }
};

struct TlvPrjModel {
    QString name;
    QString hex_file;  // 烧录文件路径
    QList<CmdPageModel> cmds;
    QList<CodePageModel> codes;

    bool operator==(const TlvPrjModel& other) const {
        return name == other.name &&
               hex_file == other.hex_file &&
               cmds == other.cmds &&  // QList 已经重载了 == 运算符
               codes == other.codes;  // QList 已经重载了 == 运算符
    }

    bool operator!=(const TlvPrjModel& other) const {
        return !(*this == other);
    }
};

#endif // TLVDATAMODELTYPEDEF_H
